package com.qiyuexinxi.chat.controller;

import com.qiyuexinxi.chat.common.GenericResponse;
import com.qiyuexinxi.chat.constants.api.UserApi;
import com.qiyuexinxi.chat.domain.Asset;
import com.qiyuexinxi.chat.dto.request.FileUploadRequest;
import com.qiyuexinxi.chat.dto.request.GetUserInfoRequest;
import com.qiyuexinxi.chat.dto.request.UpdateUserRequest;
import com.qiyuexinxi.chat.dto.request.UserAddRequest;
import com.qiyuexinxi.chat.service.UserService;
import com.qiyuexinxi.chat.service.impl.UserServiceImpl;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author yangxingyu
 * @date 2020/2/25
 * @description
 */
@RestController
@Api(description = "用户管理")
public class UserController {

    @Autowired
    UserServiceImpl userService;

    @PostMapping(value = UserApi.FILE_UPLOAD,  produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "上传用户图片", notes = "上传用户图片")
    public GenericResponse fileUpload(@Valid @ApiParam(name = "userId",value = "上传用户ID，",required = true)@RequestParam("userId")@NotNull(message = "用户ID不能为空")Integer userId,
                                      @ApiParam(name = "pictureType",value = "图片类型 0用户信息 1背景 2动态",required = true) @RequestParam("pictureType")@NotNull(message = "图片类型不能为空")Integer pictureType,
                                      @ApiParam(value="上传图片",required=true) @RequestParam("pictureImg")@NotNull(message = "上传图片不能为空")MultipartFile pictureImg){
        return new GenericResponse(userService.fileUpload(userId,pictureType,pictureImg));
    }

    @GetMapping(value = UserApi.GET_USER_INFO, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "获取用户信息", notes = "获取用户信息")
    public GenericResponse getUserInfo(@Valid GetUserInfoRequest getUserInfoRequest){
        return new GenericResponse(userService.getUserInfo(getUserInfoRequest));
    }

    @PostMapping(value = UserApi.UPDATE_USER_INFO, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改用户信息", notes = "修改用户信息")
    public GenericResponse updateUserInfo(@Valid @RequestBody UpdateUserRequest updateUserRequest){
        return new GenericResponse(userService.updateUserInfo(updateUserRequest));
    }

}
